package group2projman;

import java.text.SimpleDateFormat;

public class Payment extends Transaction {
	/// In pence
	int amount;
	
	public Payment(int id, int pAmount) {
		super(id, Transaction.Type.PAYMENT);
		
		amount = pAmount;
	}
	
	public String listAttributes() {
		StringBuffer result = new StringBuffer(super.listAttributes());
		
		result.append(",str:bookCopyId;").append(0);
		result.append(",dat:dueDate;").append(0);
		result.append(",int:lateFee;").append(0);
		result.append(",int:").append("amount;").append(amount);
		result.append(",STR:description;").append(0);
		
		return result.toString();
	}
	public boolean loadAttributes(String desc) {
		if (super.loadAttributes(desc))
			return true;
		
		try {
			String[] split = desc.split("[;,]");	
			
			if (!split[12].equals("int:amount"))
				return true;
			amount = Integer.parseInt(split[13]);
		}  catch (Exception e) {
			// Array index out of bounds or enum value not found
			return true;
		}
		
		return false;
	}		
}
